package com.example.k8s.hello.service.exam.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.example.k8s.hello.common.annotation.SysLog;
import com.example.k8s.hello.common.bean.Page;
import com.example.k8s.hello.bean.exam.entity.EdExamEntity;
import com.example.k8s.hello.bean.exam.form.EdExamSaveForm;
import com.example.k8s.hello.bean.exam.query.EdExamQuery;
import com.example.k8s.hello.bean.exam.query.EdUserQuery;
import com.example.k8s.hello.bean.exam.vo.EdExamVo;
import com.example.k8s.hello.bean.exam.vo.EdUserScoreVo;
import com.example.k8s.hello.service.exam.service.EdExamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 考试
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/ed/exam")
@Tag(name = "考试")
@RequiredArgsConstructor
public class EdExamController {
	private final EdExamService edExamService;
	
	/**
	 * 考试分页
	 */
	@Operation(summary = "考试分页")
	@GetMapping("/list")
	@SaCheckPermission("ed:exam:list")
	public Page<EdExamEntity> list(@ParameterObject EdExamQuery query, @ParameterObject Page page){
		return edExamService.queryPage(query, page);
	}

	/**
	 * 用户成绩分页
	 */
	@Operation(summary = "用户成绩分页")
	@GetMapping("/user-score-list")
	@SaCheckPermission("ed:exam:list")
	public Page<EdUserScoreVo> userScoreList(@ParameterObject EdUserQuery query, @ParameterObject Page page){
		return edExamService.queryUserScorePage(query, page);
	}

	/**
	 * 考试详情
	 */
	@Operation(summary = "考试详情")
	@GetMapping("/info/{examId}")
	@SaCheckPermission("ed:exam:info")
	public EdExamVo info(@PathVariable("examId") Long examId){
		return edExamService.getVoById(examId);
	}

	/**
	 * 保存考试（返回考试详情）
	 */
	@Operation(summary = "保存考试（返回考试详情）")
	@SysLog("保存考试")
	@PostMapping("/save")
	@SaCheckPermission("ed:exam:save")
	public EdExamVo save(@RequestBody @Validated EdExamSaveForm form){
		return edExamService.saveExam(form);
	}

//	/**
//	 * 修改考试
//	 */
//	@Operation(summary = "修改考试")
//	@SysLog("修改考试")
//	@PostMapping("/update")
//	@SaCheckPermission("sys:config:update")
//	public void update(@RequestBody @Validated EdExamEntity config){
//		edExamService.update(config);
//	}
//

	/**
	 * 删除考试
	 */
	@Operation(summary = "删除考试")
	@SysLog("删除考试")
	@PostMapping("/delete")
	@SaCheckPermission("ed:exam:delete")
	public void delete(@RequestBody Long[] examIds){
		edExamService.deleteBatch(examIds);
	}

}
